package org.mech.sefer.event.bus;

import org.mech.sefer.event.EventSource;
import org.mech.sefer.event.Handler;
import org.mech.sefer.event.register.HandlerRegistration;
import org.mech.sefer.event.register.HandlerRegistrationInfo;

/**
 * <p>
 * The EventBus is mechanism for event driven comunication between components.
 * {@link Handler} can be registered to listen on given event class, so if event
 * ocurred it will be distributed to all handlers.
 * </p>
 * <p>
 * Handler will be registered automaticly or lazy if
 * {@link HandlerRegistrationInfo} is set that way. When registering
 * {@link HandlerRegistration} is obtained wich acts like simple attach/detach
 * mechanism for desired handler
 * </p>
 * <p>
 * Date: 24.4.2012 8:31:21
 * </p>
 * 
 * @author martin.krajc
 */
public interface EventBus extends EventSource {

	/**
	 * Register handler on event bus.
	 *
	 * @param eventClass the event class
	 * @param handler the handler to register
	 * @return the handler registration
	 */
	HandlerRegistration registerHandler(Class<?> eventClass, Handler handler);

	/**
	 * Register handler register handler for given event type into event bus.
	 * You can pass registration config through {@link HandlerRegistrationInfo}
	 *
	 * @param eventClass the event class
	 * @param handler  the handler to register
	 * @param info the configuration info for registration
	 * @return the handler registration 
	 */
	HandlerRegistration registerHandler(Class<?> eventClass, Handler handler, HandlerRegistrationInfo info);

}
